package com.ruoyi.web.controller.novel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNovelBook;
import com.ruoyi.system.service.ISysNovelBookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书籍列表Controller
 *
 * @author ZouYangMing
 * @date 2022-11-08
 */
@RestController
@RequestMapping("/novel/book")
public class SysNovelBookController extends BaseController
{
    @Autowired
    private ISysNovelBookService sysNovelBookService;

    /**
     * 查询书籍列表列表
     */
    //@PreAuthorize("@ss.hasPermi('novel:book:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(SysNovelBook sysNovelBook)
    {
        startPage();
        List<SysNovelBook> list = sysNovelBookService.selectSysNovelBookList(sysNovelBook);
        return getDataTable(list);
    }

    /**
     * 导出书籍列表列表
     */
    @PreAuthorize("@ss.hasPermi('novel:book:export')")
    @Log(title = "书籍列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNovelBook sysNovelBook)
    {
        List<SysNovelBook> list = sysNovelBookService.selectSysNovelBookList(sysNovelBook);
        ExcelUtil<SysNovelBook> util = new ExcelUtil<SysNovelBook>(SysNovelBook.class);
        util.exportExcel(response, list, "书籍列表数据");
    }

    /**
     * 获取书籍列表详细信息
     */
    //@PreAuthorize("@ss.hasPermi('novel:book:query')")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysNovelBookService.selectSysNovelBookById(id));
    }

    /**
     * 新增书籍列表
     */
    @PreAuthorize("@ss.hasPermi('novel:book:add')")
    @Log(title = "书籍列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNovelBook sysNovelBook)
    {
        return toAjax(sysNovelBookService.insertSysNovelBook(sysNovelBook));
    }

    /**
     * 修改书籍列表
     */
    @PreAuthorize("@ss.hasPermi('novel:book:edit')")
    @Log(title = "书籍列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNovelBook sysNovelBook)
    {
        return toAjax(sysNovelBookService.updateSysNovelBook(sysNovelBook));
    }

    /**
     * 删除书籍列表
     */
    @PreAuthorize("@ss.hasPermi('novel:book:remove')")
    @Log(title = "书籍列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysNovelBookService.deleteSysNovelBookByIds(ids));
    }

    /**
     * 查询书籍列表按字数排序
     */
    @Anonymous
    @GetMapping("/ListBookFontNumber")
    public AjaxResult selectSysNovelBookListBookFontNumber()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookFontNumber());
    }

    /**
     * 查询书籍按出版时间排序
     */
    @Anonymous
    @GetMapping("/ListBookStartTime")
    public AjaxResult selectSysNovelBookListBookStartTime()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookStartTime());
    }

    /**
     * 查询书籍按购买数量排序
     */
    @Anonymous
    @GetMapping("/ListBookPayNumber")
    public AjaxResult selectSysNovelBookListBookPayNumber()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookPayNumber());
    }

    /**
     * 查询书籍按完结时间排序
     */
    @Anonymous
    @GetMapping("/ListBookEndTime")
    public AjaxResult selectSysNovelBookListBookEndTime()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookEndTime());
    }

    /**
     * 查询书籍按浏览量排序
     */
    @Anonymous
    @GetMapping("/ListBookBrowseNumber")
    public AjaxResult selectSysNovelBookListBookBrowseNumber()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookBrowseNumber());
    }

    /**
     * 查询书籍按收藏量排序
     */
    @Anonymous
    @GetMapping("/ListBookCollectionNumber")
    public AjaxResult selectSysNovelBookListBookCollectionNumber()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookCollectionNumber());
    }

    /**
     * 查询书籍按更新时间排序
     */
    @Anonymous
    @GetMapping("/ListBookUpdateTime")
    public AjaxResult selectSysNovelBookListBookUpdateTime()
    {
        return success(sysNovelBookService.selectSysNovelBookListBookUpdateTime());
    }
}
